<template>
  <view>
   <!-- 选择收货地址 -->
   <view class="address-choose-box" v-if="JSON.stringify(address) === '{}'">
     <button type="primary" size="mini" class="btn-choose-btn" @click="chooseAddress">
       请选择收货地址+
     </button>
   </view>
   <!-- 渲染收货信息的盒子 -->
   <view @click="chooseAddress" class="address-info-box" v-else>
     <view class="row1">
       <view class="row1-left">
         <view class="username">
           收货人: {{address.userName}}
         </view>
       </view>
       <view class="row1-right">
         <view class="phone">
           电话: {{address.telNumber}}
         </view>
         <uni-icons type="right" size="16"></uni-icons>
       </view>
     </view>
     <view class="row2">
       <view class="row2-left">
         收货地址: 
       </view>
       <view class="row2-right">
         {{ad}}
       </view>
     </view>
   </view>
    <!-- 底部边框线 -->
    <image src="/static/cart_border@2x.png" class="address-border"></image>
  </view>
</template>

<script>
  import {mapState,mapGetters,mapMutations} from 'vuex'
  export default {
    name:"my-adress",
    data() {
      return {
        
      };
    },
    methods: {
     async chooseAddress() {
       const [err,success] = await uni.chooseAddress().catch(err => err)
       // console.log(res)
       if(err === null && success.errMsg === "chooseAddress:ok") {
         // console.log(success)
         this.updateAddress(success)
         this.storageAddress(success)
       }
      console.log(err)
      },
      ...mapMutations('m_user',['updateAddress']),
      ...mapMutations('m_user',['storageAddress'])
    },
    computed: {
      ...mapState('m_user',['address']),
      ...mapGetters('m_user',['ad'])
    }
  }
</script>

<style lang="scss">
  .address-choose-box {
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    
  }
.address-border {
  display: block;
  width: 100%;
  height: 5px;
}
.address-info-box {
  padding: 0 5px;
  height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-size: 12px;
  .row1 {
    display: flex;
    justify-content: space-between;
    .row1-right {
      display: flex;
    }
  }
  .row2 {
    display: flex;
    padding-top: 10px;
    align-items: center;
    .row2-left {
      // width: 65px;
      padding-right: 5px;
    }
    .row2-right {
      flex: 1;
    }
  }
}
</style>